#include "EyerWASMIndexedDB_CloseEvent.hpp"

#include <emscripten.h>

extern "C"
{
EMSCRIPTEN_KEEPALIVE int EyerWASMIndexedDB_CloseEvent_Close(void * ctx, int indexedDBKey);
EMSCRIPTEN_KEEPALIVE int EyerWASMIndexedDB_CloseEvent_Close_OnSucc(void * ctx)
{
    Eyer::EyerWASMIndexedDB_CloseEvent * event = (Eyer::EyerWASMIndexedDB_CloseEvent *)ctx;
    return event->EyerWASMIndexedDB_CloseEvent_Close_OnSucc();
}
}

namespace Eyer
{
    EyerWASMIndexedDB_CloseEvent::EyerWASMIndexedDB_CloseEvent(int indexedDBKey)
    {
        m_indexedDBKey = indexedDBKey;
    }

    EyerWASMIndexedDB_CloseEvent::~EyerWASMIndexedDB_CloseEvent()
    {

    }

    int EyerWASMIndexedDB_CloseEvent::Run()
    {
        EyerWASMIndexedDB_CloseEvent_Close(this, m_indexedDBKey);
        return 0;
    }

    int EyerWASMIndexedDB_CloseEvent::EyerWASMIndexedDB_CloseEvent_Close_OnSucc()
    {
        std::unique_lock<std::mutex> lck(mtx);
        isSucced = true;
        isFinished = true;
        cond.notify_all();
        return 0;
    }
}